<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索</legend>
            <div style="margin: 10px 10px 10px 10px" id="btn">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">文件名称</label>
                            <div class="layui-input-inline">
                                <!--注意此处input标签里的id-->
                                <input class="layui-input" name="keyword" id="demoReload" autocomplete="off">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <!--注意此处button标签里的type属性-->
                            <button type="button" class="layui-btn layui-btn-primary data-search-btn"  lay-submit data-type="reload" lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <!--注意此处table标签里的id-->
        <table class="layui-table layui-hide" id="dataTable" lay-filter="dataTable"></table>
    </div>
</div>
{include file="block/layui" /}
<script type="text/html" title="删除" id="buttonTpl">
    <a href="{:url('del')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
</script>

<script type="text/javascript">
    layui.use(['table'], function() {
        var table = layui.table , $=layui.jquery , from= layui.from;
        var suffix = ['jpg','png','gif','svg','ico'];
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter','exports']
            ,cols: [[ //表头
                {field: 'name', title: '文件名称' , width:'161' , align:"center"}
                ,{field: 'type', title: '类型' , width:'100' , align:"center"}
                ,{field: 'size', title: '大小' , width:'100' , align:"center"}
                ,{field: 'suffix', title: '后缀' , width:'60' , align:"center"}
                ,{field: 'url', title: '域名', templet:function(d){
                        if(suffix.includes(d.suffix)){
                            $(document).on('click','.imageclick', function(){
                                if($(this).attr('data-id')==d.id){
                                    $.getJSON('{:url("image")}?id='+d.id, function(json){
                                        layer.photos({
                                            photos: json
                                            ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                                        });
                                    });
                                }
                            });
                            return '<img src="'+"{:config('aly_config.oss_upload_url')}"+d.url+'" data-id="'+d.id+'" class="imageclick"/>';
                        }else{
                            return d.url;
                        }
                    } , width:'160' , align:"center"}
                ,{field: 'success', title: '返回信息' , width:'100' , align:"center"}
                ,{field: 'ctime', title: '时间' , width:'100' , align:"center"}
                ,{title: '操作', templet: '#buttonTpl' , width:'50' , align:"center"}
            ]]
        });

        //以下是搜索框进行监测
        var active = {
            reload: function(){
                var demoReload = $('#demoReload');	//得到搜索框里已输入的数据
                //执行重载
                table.reload('dataTable', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        name:  demoReload.val()		//在表格中进行搜索
                    }
                });
            }
        };

        $('.data-search-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>